package com.example.blogemail.job;

import com.alibaba.fastjson.JSON;
import com.example.blogemail.eneity.Email;
import com.example.blogemail.service.emailService;
import com.yz.core.dto.EmailDto;
import com.yz.core.utils.EmailUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @className: SendGetLostEmaill
 * @author: shuishui
 * @date: 2023/02/03 20:11
 */
@Component
@Slf4j
public class SendGetLostEmail {
    @Autowired
    private com.example.blogemail.service.emailService emailService;
    @Scheduled(cron = "0/10 * * * * * ")//秒，分，时，天，月，周，年------十秒跑一次
    public void sendEmail(){
        List<Email> erroremail = getErroeEmails();
        for(Email errorEmail : erroremail){
            String emilText = errorEmail.getEmailText();
            try {
                EmailUtils.sendEmailInfoUser(JSON.parseObject(emilText, EmailDto.class));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        log.debug("邮件回家喽");
    }

    private List<Email> getErroeEmails() {
        return null;
    }


}
